package com.opennews.openplatform.controller;

import com.opennews.openplatform.myspringbootcore.dto.ApiResponse;
import com.opennews.openplatform.myspringbootcore.helper.AMapHelper;
import com.opennews.openplatform.myspringbootmvccore.helper.HttpResponseHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/map-location")
public class MapLocationController {
    private final AMapHelper amapHelper;
    private final HttpResponseHelper httpResponseHelper;

    @GetMapping("/query-by-coordinate")
    public ResponseEntity<ApiResponse<Map<String, Object>>> queryByCoordinate(@RequestParam double latitude, @RequestParam double longitude) {
        Map<String, Object> result = amapHelper.queryByCoordinate(latitude, longitude);

        return httpResponseHelper.getSuccessResponse(result);
    }

    @GetMapping("/query-poi-by-keywords")
    public ResponseEntity<ApiResponse<List<Map<String, Object>>>> queryPoiByKeywords(@RequestParam String keywords) {
        List<Map<String, Object>> result = amapHelper.queryPoiByKeywords(keywords);

        return httpResponseHelper.getSuccessResponse(result);
    }
}
